package com.coolbi.onsupai.core.biz.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.coolbi.onsupai.core.biz.MerchantBiz;
import com.coolbi.onsupai.core.dao.MerchantDao;
import com.coolbi.onsupai.core.entity.Merchant;
import com.coolbi.onsupai.core.exception.ServiceException;

public class MerchantBizImpl implements MerchantBiz {

	@Autowired
	private MerchantDao merchantDao;
	
	public void setMerchantDao(MerchantDao merchantDao) {
		this.merchantDao = merchantDao;
	}

	@Override
	public Merchant save(Merchant obj) {
		try {
			merchantDao.save(obj);
		} catch (Exception e) {
			throw new ServiceException("添加供应商信息发生错误！", e);
		}
		return obj;
	}

	@Override
	public void delete(long id) {
		try{
			merchantDao.delete(id);
		}catch(Exception e)
		{
			throw new ServiceException("删除供应商信息发生错误！", e);
		}
	}

	@Override
	public void update(Merchant obj) {
		try{
			merchantDao.update(obj);
		}catch(Exception e)
		{
			throw new ServiceException("更新供应商信息发生错误！", e);
		}
	}

	@Override
	public Merchant get(long id) {
		return merchantDao.get(id);
	}

	@Override
	public List<Merchant> list() {
		return merchantDao.list();
	}

	@Override
	public List<Merchant> listByPage(int offset, int limit) {
		return merchantDao.listByPage(offset, limit);
	}

	@Override
	public List<Merchant> find(Map<String, Object> parameter) {
		return merchantDao.find(parameter);
	}

	@Override
	public List<Merchant> findByPage(Map<String, Object> parameter, int offset,
			int limit) {
		return merchantDao.findByPage(parameter, offset, limit);
	}

	@Override
	public List<Merchant> search(Map<String, Object> parameter, int offset,
			int limit) {
		return merchantDao.search(parameter, offset, limit);
	}

	@Override
	public int count() {
		return merchantDao.count();
	}

	@Override
	public int countByKeyWord(Map<String, Object> parameter) {
		return merchantDao.countByKeyWord(parameter);
	}

	@Override
	public int count(Map<String, Object> parameter) {
		return merchantDao.count(parameter);
	}

	@Override
	public boolean checkMerchantNo(String merchantNo) {
		return merchantDao.countByMerchantNo(merchantNo) > 0;
	}

	@Override
	public boolean checkTelephone(String telephone) {
		return merchantDao.countByTelephone(telephone) > 0;
	}

	@Override
	public boolean checkEmail(String email) {
		return merchantDao.countByEmail(email) > 0;
	}

}
